﻿using System;
using System.Windows;
using PengSW.WindowHelper;

namespace MultiLanguage_AnalyzeProject
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private MultiLanguageModel Model => this.DataContext as MultiLanguageModel;

        private void OnAnalyze_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog aDlg = new System.Windows.Forms.FolderBrowserDialog();
            if (aDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            this.Exec(() =>
            {
                Model.Analyze(aDlg.SelectedPath);
                MessageBox.Show("分析完毕！");
            });
        }

        private void OnAnalyze_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void OnImportExcel_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog aDlg = new Microsoft.Win32.OpenFileDialog
            {
                Title = "选择文件",
                DefaultExt = "*.xlsx",
                Filter = "Excel File (*.xlsx)|*.xlsx|All Files (*.*)|*.*",
            };
            if (aDlg.ShowDialog() != true) return;
            this.Exec(() =>
            {
                Model.ImportExcel(aDlg.FileName);
                MessageBox.Show("导入完毕！");
            });
        }

        private void OnImportExcel_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void OnUpgrade_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog aDlg = new System.Windows.Forms.FolderBrowserDialog();
            if (aDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            this.Exec(() =>
            {
                Model.Upgrade(aDlg.SelectedPath);
                MessageBox.Show("更新完毕！");
            });
        }

        private void OnUpgrade_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void OnCreateXaml_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog aDlg = new System.Windows.Forms.FolderBrowserDialog();
            if (aDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            this.Exec(() =>
            {
                Model.CreateXaml(aDlg.SelectedPath);
                MessageBox.Show("生成完毕！");
            });
        }

        private void OnCreateXaml_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void OnExportExcel_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            this.Exec(() =>
            {
                Model.ExportExcel();
                MessageBox.Show("导出完毕！");
            });
        }

        private void OnExportExcel_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
    }
}
